package com.e9ab98e991ab.librepository.api;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
 * @author gaoxin 18-11-7 上午11:17
 * @version V1.0.0
 * @name Resource
 */
public class Resource<T> {

    @NonNull
    private final Status mStatus;

    @Nullable
    private final String mMessage;

    @Nullable
    private final T mData;

    private Resource(@NonNull Status status, @Nullable T data, @Nullable String message){
        mStatus = status;
        mData = data;
        mMessage = message;
    }

    public static <T> Resource<T> success(@Nullable T data){
        return new Resource<>(Status.SUCCESS, data, null);
    }

    public static <T> Resource<T> error(String msg , @Nullable T data){
        return new Resource<>(Status.ERROR, data, msg);
    }

    public static <T> Resource<T> loading(@Nullable T data) {
        return new Resource<>(Status.LOADING, data, null);
    }

    @NonNull
    public Status getStatus() {
        return mStatus;
    }

    @Nullable
    public String getMessage() {
        return mMessage;
    }

    @Nullable
    public T getData() {
        return mData;
    }

    @Override
    public String toString() {
        return "Resource{" +
                "mStatus=" + mStatus +
                ", mMessage='" + mMessage + '\'' +
                ", mData=" + mData +
                '}';
    }
}
